
var ctx = ctx;
$(function(){
    var val=$('input:radio[name="deptPatient"]:checked').val();
    if (val==undefined || val == '1') {
        $("#dc_waitNewInPatientList").show();
        $("#dc_waitTurnInPatientList").hide();
        loadDiv('dc_waitNewInPatientList',ctx+'/doctor/medicalRecord/waitDeptPatientList');
    } else {
        $("#dc_waitNewInPatientList").hide();
        $("#dc_waitTurnInPatientList").show();
        loadDiv('dc_waitTurnInPatientList',ctx+'/doctor/medicalRecord/allwaitDeptPatientList');
    }


    /*身份证号回车事件，验证身份证所属人是否是待入科*/
    $("#idNo").keydown(function(e){
        var idNo = $("#idNo").val();
        if (e.keyCode == 13) {
            validIdCard(idNo);
            return false;
        }
    });
});

//选中单选按钮，更改radio选中值
function changeRadio(obj) {
    $('input:radio[value='+obj+']').prop("checked",true);
    funItem(obj);
}
//病人列表切换
function funItem(obj) {
    if (obj == '1') {
        $("#dc_waitNewInPatientList").show();
        $("#dc_waitTurnInPatientList").hide();
        loadDiv('dc_waitNewInPatientList',ctx+'/doctor/medicalRecord/waitDeptPatientList');
    } else {
        $("#dc_waitNewInPatientList").hide();
        $("#dc_waitTurnInPatientList").show();
        loadDiv('dc_waitTurnInPatientList',ctx+'/doctor/medicalRecord/allwaitDeptPatientList');
    }
}

function validIdCard(idNo){
    $.ajax({
        type: 'POST',
        url: ctx + '/doctor/medicalRecord/validIdCard?idNo='+idNo,
        contentType: 'application/json',
        dataType: 'json',
        success: function (data) {
            if (data.code=="success") {
                loadDiv('dc_turnInPatient',ctx+'/doctor/medicalRecord/findInfoByParam?idNo='+idNo);
            } else{
                toastr.info('该病人已入科室或者不存在');
                return;
            }
        }, error: function (data) {
            toastr.error('网络连接失败！');
        }
    });
}

function saveTurnInLoad(divId,formId,url,hrefUrl){
        if(flag){
            if ($('#' + formId).parsley().validate()) {
                flag = false;
                $("#" + formId + " input,#" + formId + " select").removeAttr("disabled");
                $.ajax({
                    type: "POST",
                    data: $("#" + formId).serialize(),
                    url: url,
                    dataType: "json",
                    success: function (data) {
                        if (data.code == "success") {
                            toastr.success(data.data);
                            parent.layer.closeAll(); //关闭当前弹层
                            parent.$("#searchForm").submit();
                            // loadDiv(divId,hrefUrl);

                        } else {
                            flag = true;
                            toastr.error(data.data);
                        }
                    },
                    error: function (data) {
                        toastr.error('网络连接错误,请检查网络');
                        flag = true;
                    }
                });
            }
        }
        return false;
    }




